<?php
namespace app\adminxcx\controller;
use \think\Controller;
use app\admin\model\User as UserModel;
use app\admin\model\Card as CardModel;
use app\admin\model\Group as GroupModel;


class Index extends Controller
{

    protected $UserModel;
    protected $CardModel;
    protected $GroupModel;

    public function __construct()
    {
        $this->UserModel = new UserModel();
        $this->CardModel = new CardModel();
        $this->GroupModel = new GroupModel();
    }

    public function index($uid=0,$token)
    {
        session('uid', $uid);
        if(!$token || $token != cache('token_admin'.$uid)){
            return view('login/index',[
                'uid' => $uid
            ]);
        }
        $userRes = $this->UserModel->get($uid);
        if($userRes){
            if($userRes->cid){  
                $res = $this->CardModel->get($userRes->cid);
                if($res){
                    $group = $this->GroupModel->get($res->gid);
                    session('adminLevel', $group->level);
                    return view('index/index',[
                        'card' => $res,
                        'uid' => $uid
                    ]);
                }else{
                    return view('login/index',[
                        'uid' => $uid
                    ]);
                }
            }else{
                return view('login/index',[
                    'uid' => $uid
                ]);
            }
        }else{
            return view('login/index',[
                'uid' => $uid
            ]);
        } 
    }


    public function upload(){
        if(!session('uid')){
            return 0;
        }
        $fileinfo = $_FILES['file'];
        $file = request()->file('file');
        $info = $file-> move(env('ROOT_PATH').'public/uploads');
        $image = str_replace('\\','/',$info->getSaveName()); 
        print_r($image);
    }
    

 
}
